    //
//  SetingTableViewController.m
//  IconMaster
//
//  Created by mac on 2017/7/26.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "SetingTableViewController.h"
#import <SDImageCache.h>
#define CellID @"cell0"
@interface SetingTableViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSArray *titleArr;
@property (nonatomic, strong) UIImageView *navImage;
@property (strong, nonatomic)  UIView *adView;
@end

@implementation SetingTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.automaticallyAdjustsScrollViewInsets =NO;
//    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
    [self setImageViewINNav];
    self.titleArr = @[@"版本",@"分享",@"反馈",@"清除缓存",@"去评分",@"帮助"];
//    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellID];
//    self.tableView.sd_layout.topSpaceToView(_navImage, 64);
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
//    [self initAdmob];
   
}
- (void)setImageViewINNav{
    
    _navImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, -64, KWidth, 64)];
    _navImage.image = [UIImage imageNamed:@"navall"];
    [self.view addSubview:_navImage];
    [_navImage sendSubviewToBack:self.view];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return self.titleArr.count;
}
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//    return @"关于";
//}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    static NSString *ID = @"cell0";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellID];
    }
    cell.textLabel.text = NSLocalizedString(self.titleArr[indexPath.row],"");
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row !=0) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    if (indexPath.row == 0) {
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
        CFShow((__bridge CFTypeRef)(infoDictionary));  
        // app名称  
//        NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];  
        // app版本  
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];  
        // app build版本  
//        NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];  
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",app_Version];
//        NSLog(@"cell.detailTextLabel.text = %@", cell.detailTextLabel.text);
//        cell.detailTextLabel.textColor = [UIColor redColor];
    }else{
    
    }
    // Configure the cell...
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 1) {
        //分享
        NSDictionary *shareDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"shareDict"];
        NSString *textToShare = NSLocalizedString(shareDict[@"description"], nil) ; 
        
        UIImage *imageToShare = [UIImage imageNamed:@"icon"]; 
        
        NSURL *urlToShare = [NSURL URLWithString:shareDict[@"shareUrl"]];
        
        NSArray *activityItems = @[textToShare, imageToShare, urlToShare];
        
        UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
        [self presentViewController:activityVC animated:YES completion:nil];
 
    }
    if (indexPath.row == 2) {
        //反馈
        [self performSegueWithIdentifier:@"feedback" sender:self];
    }
    if (indexPath.row == 3) {
        //清除缓存
        [[SDWebImageManager sharedManager].imageCache clearMemory];
        UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"已清除缓存" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alter show];
    }
    if (indexPath.row == 4) {
        //去评分673530545 itms-apps://itunes.apple.com/app/id673530545
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/app/id673530545"] options:@{} completionHandler:^(BOOL success) {
            //成功
        }];
    }
    if (indexPath.row == 5) {
        //关于
        [self performSegueWithIdentifier:@"about" sender:self];
    }
}
- (void)initAdmob
{
    self.adView = [[UIView alloc] initWithFrame:CGRectMake(0, KHeight - 80, KWidth, 80)];
    [self.view addSubview:self.adView];
    [self.view bringSubviewToFront:self.adView];
    GADBannerView* bannerView =
    [AdAndHint showBannerViewInController:self view:self.view frame:CGRectZero];
    CGRect bannerFrame = bannerView.frame;
    bannerFrame.origin.x = 0;
    bannerFrame.origin.y = KHeight -10-bannerFrame.size.height;
    bannerView.frame = bannerFrame;
    [self.adView addSubview:bannerView];
    bannerView.sd_layout.topEqualToView(self.adView).leftEqualToView(self.adView).rightEqualToView(self.adView).bottomEqualToView(self.adView);
    //    bannerView.autoresizingMask = segmentControl.autoresizingMask;
    
    [AdAndHint loadInterstitialIfNeed];
    self.adView.sd_layout.heightIs(80).topSpaceToView(self, KHeight - 200);
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
